package com.example.mycount2text;

import androidx.appcompat.app.AppCompatActivity;

import android.app.AlertDialog;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.material.snackbar.Snackbar;

import org.w3c.dom.ls.LSOutput;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;

public class TheTransform extends AppCompatActivity  {
    private Button cul;
    private TextView sex;
    private EditText Up,Down,Middle;
    private LinearLayout parent;
    private int sexTrigger=0;
    private ImageButton man,woman;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.themenuspinner);
        Up = findViewById(R.id.Up1);
        Middle = findViewById(R.id.Middle);
        Down = findViewById(R.id.Down1);
        cul = findViewById(R.id.cul);
        sex =findViewById(R.id.sex);
        parent=findViewById(R.id.parent);
        man=findViewById(R.id.Man);
        woman=findViewById(R.id.Woman);
        woman.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                sexTrigger =2;
                sex.setText("性别(女)");
                sex.setTextColor(view.getResources().getColor(R.color.girl_red));
            }
        });
        man.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                sexTrigger =1;
                sex.setText("性别(男)");
                sex.setTextColor(view.getResources().getColor(R.color.low_blue));
            }
        });
        cul.setOnClickListener(new View.OnClickListener() {
            @Override

            public void onClick(View view) {
                String a =Up.getText().toString();
                String b =Middle.getText().toString();
                String c =Down.getText().toString();
                if(a.equals("")||b.equals("")||c.equals(""))
                    showSnackbar(1);
                else if (sex.getText().equals("性别"))
                {
                    showSnackbar(2);
                }
                else{
                    Double TheMessagerA = new Double(a);
                    Double TheMessagerB = new Double(b);
                    Double TheMessagerC = new Double(c);
                    TheMessagerB=TheMessagerB/100;
                    BigDecimal bg = new BigDecimal(TheMessagerC/TheMessagerB/TheMessagerB).setScale(2, RoundingMode.UP);
                    BuilderAlter(bg.doubleValue());
                }
            }
        });
}
    public void BuilderAlter(double Msg){
        AlertDialog alertDialog1 = new AlertDialog.Builder(this)
                .setTitle("您的体重指数")//标题
                .setMessage("您的体重是"+Msg)//内容
                .setIcon(R.drawable.thewoman1_foreground)//图标
                .create();
        alertDialog1.show();
    }
    private void showSnackbar(int info) {
        if(info==1)
        Snackbar.make(parent, "您输入有空项!", Snackbar.LENGTH_SHORT).setAction("清空数据栏", new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Up.setText("");
                Down.setText("");
                Middle.setText("");
            }
        }).setActionTextColor(Color.RED)
                .setTextColor(Color.YELLOW)
                .show();
        else
            Snackbar.make(parent, "您没有选性别!", Snackbar.LENGTH_SHORT).setAction("好的", new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                }
            }).setActionTextColor(Color.RED)
                    .setTextColor(Color.YELLOW)
                    .show();

    }
}
